package com.imooc.ecommerce.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 品牌分类
 *
 * @author zhangshao
 * @since 2023/11/29 21:35
 */
@Getter
@AllArgsConstructor
public enum BrandCategory {
    BRAND_A("20001", "品牌 A"),
    BRAND_B("20002", "品牌 B"),
    BRAND_C("20003", "品牌 C"),
    BRAND_D("20004", "品牌 D"),
    BRAND_E("20005", "品牌 E"),

    ;
    /**
     * 品牌分类编码
     */
    @EnumValue
    private final String code;

    /**
     * 品牌分类描述信息
     */
    @JsonValue
    private final String description;

    /**
     * 根据code 获取到BrandCategory
     */
    public static BrandCategory of(String code) {
        Objects.requireNonNull(code);
        return Stream.of(BrandCategory.values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(
                () -> new IllegalArgumentException(code + "not exists")
        );
    }
}
